package testclient;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;

/* OK, let's try pass string A and print string B */

public class TClient {
	public static void main(String args[]) {

		// Construct data
		String Login_Credential;
		try {
			Login_Credential = "username=dummy&password=foobar";
			
			// Send data
			URL url = new URL("http://107.22.164.227:8080/ServletHost/login");
//			URL url = new URL("http://localhost:8080/ServletHost/servlet");
			
			URLConnection conn = url.openConnection();


			conn.setDoOutput(true);
			OutputStreamWriter wr = new OutputStreamWriter(
					conn.getOutputStream());
			wr.write(Login_Credential);
			wr.flush();

			// Get the response
			BufferedReader rd = new BufferedReader(new InputStreamReader(
					conn.getInputStream()));
			String line;
			while ((line = rd.readLine()) != null) {
				// Process line...
				System.out.println(line);
			}
			rd.close();
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
